<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/3/11
  Time: 11:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--导入核心标签库--%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>公共页面</title>
<%--    导包--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css"  />
    <script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js" ></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js" ></script>
</head>
<body>
<%--包含logo和导航栏部分--%>
<div class="container-fluid">

    <!--
        描述：菜单栏
    -->
    <div class="container-fluid">
        <div class="col-md-4">
            <img src="${pageContext.request.contextPath}/img/logo2.png" />
        </div>
        <div class="col-md-5">
            <img src="${pageContext.request.contextPath}/img/header.png" />
        </div>
        <div class="col-md-3" style="padding-top:20px">
            <ol class="list-inline">
                <c:if test="${empty user}">
                    <li><a href="${pageContext.request.contextPath}/user?methodName=loginUI">登录</a></li>
                    <!--${pageContext.request.contextPath} 通过pageContext域对象获取request bean属性同时通过
                    request对象获取contextPath这个bean属性,获取上下文路径
                    等价于pageContext.getRequest().getcontextPath()
                    -->
                    <li><a href="${pageContext.request.contextPath}/user?methodName=registerUI">注册</a></li>
                    <li><a href="">购物车</a></li>
                </c:if>
                <%--如果session域中的user对象不为空--%>

                <c:if test="${not empty user}">
                    <stong>欢迎,${user.name}</stong>
                    <li><a href="${pageContext.request.contextPath}/user?methodName=loginOut">退出</a></li>
                    <li><a href="${pageContext.request.contextPath}/cart?methodName=add2cart">购物车</a></li>
                    <li><a href="${pageContext.request.contextPath}/order?methodName=findOrderPage&currentPage=1&pageSize=2&oid=${order.oid}">我的订单列表</a></li>

                </c:if>
            </ol>
        </div>
    </div>
    <!--
        描述：导航条
    -->
    <div class="container-fluid">
        <nav class="navbar navbar-inverse">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="${pageContext.request.contextPath}/">首页</a>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav" id="daohangUL" >
<%--                        <li class="active"><a href="product_list.htm">手机数码<span class="sr-only">(current)</span></a></li>--%>
<%--                        <li><a href="#">电脑办公</a></li>--%>
<%--                        <li><a href="#">电脑办公</a></li>--%>
<%--                        <li><a href="#">电脑办公</a></li>--%>

                    </ul>
                    <form class="navbar-form navbar-right" role="search">
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Search">
                        </div>
                        <button type="submit" class="btn btn-default">Submit</button>
                    </form>

                </div>
                <!-- /.navbar-collapse -->
            </div>
            <!-- /.container-fluid -->
        </nav>
    </div>
    </div>

    </body>
<script>
    //提交异步请求任务
    $.get("${pageContext.request.contextPath}/category?methodName=findCategory",
        function (data) {
        //获取导航栏的ul标签对象
        //     alert(data);
            var ul = $("#daohangUL") ;
            //将服务器响应的数据遍历
            $(data).each(function () {
                //拼接li标签(Jquery的文档操作)
                //Jquery对象追加方法 append("标签")
                //<li>分类名称<li>
                /*jquery.json对象里面的key 获取value*/
                ul.append("<li><a href='${pageContext.request.contextPath}/product?methodName=findProductByPage&currentPage=1&pageSize=12&cid="+this.cid+"'>"+this.cname+"</a><span class=\"sr-only\">(current)</span></li>")
            })
    },"json");
</script>
</html>
